package shejishiyan;
import java.util.*;
//储存
public class GradeManager {
	private List<Student> students = new ArrayList<>();
    private List<Course> courses = new ArrayList<>();
    private List<Score> scores = new ArrayList<>();
    
    // 添加学生
    public void addStudent(Student student) {
        students.add(student);
    }
    
    // 添加课程
    public void addCourse(Course course) {
        courses.add(course);
    }
    
    // 添加成绩
    public void addScore(Score score) {
        scores.add(score);
    }
    
    // 计算学生GPA
    public double calculateGPA(String studentId) {
        double totalPoints = 0;
        double totalCredits = 0;
        
        for (Score score : scores) {
            if (score.getStudent().getStudentId().equals(studentId)) {
                double point = scoreToPoint(score.getScore());
                totalPoints += point * score.getCourse().getCredit();
                totalCredits += score.getCourse().getCredit();
            }
        }
        
        return totalCredits > 0 ? totalPoints / totalCredits : 0;
    }
    
    // 分数转绩点
    private double scoreToPoint(double score) {
        if (score >= 90) return 4.0;
        if (score >= 80) return 3.0;
        if (score >= 70) return 2.0;
        if (score >= 60) return 1.0;
        return 0;
    }
    
    // 查询课程成绩
    public void showCourseScores(String courseId) {
        System.out.println("课程成绩列表:");
        for (Score score : scores) {
            if (score.getCourse().getCourseId().equals(courseId)) {
                System.out.println(score.getCourse().getCourseName()+score.getStudent().getName() + ": " + score.getScore());
            }
        }
    }
    
    // 显示所有数据
    public void showAllData() {
        System.out.println("\n=== 所有学生 ===");
        for (Student s : students) {
            System.out.println(s);
        }
        
        System.out.println("\n=== 所有课程 ===");
        for (Course c : courses) {
            System.out.println(c);
        }
        
        System.out.println("\n=== 所有成绩 ===");
        for (Score sc : scores) {
            System.out.println(sc);
        }
    }
}